package com.qianfeng.smartdevice.controller;

import com.qianfeng.smartdevice.dto.R;
import com.qianfeng.smartdevice.pojo.Area;
import com.qianfeng.smartdevice.service.IAreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/areas")
public class AreaController {
    @Autowired
    private IAreaService areaService;

    /**
     * 获取所有的父区域, 也就是没有父区域的区域就是父区域
     * 元数据:描述数据的数据叫元数据
     *
     * @return
     */
    @GetMapping("/areas/parent")
    public R getAllParentArea() {
        List<Area> allParentArea = areaService.getAllParentArea();
        return R.setOk(allParentArea);
    }

    @GetMapping("/area/parent/{parentId}")
    public R getAllParentArea(@PathVariable Long parentId) {
        List<Area> areaList = areaService.getAllAreasByParentId(parentId);
        return R.setOk(areaList);
    }


}
